#include <stdio.h>
#include <string.h>
#include <math.h>

/*
 * abstract : study.
 * date     : 2010.11.30 14:55
 */

void size_len()
{
	int *p = NULL;
	int a[100];
	char *s = "xiaozhi";

	printf("sizeof(p)  : %d\n", sizeof(p));		// 4
	printf("sizeof(*p) : %d\n", sizeof(*p));	// 4

	printf("sizeof(a) : %d\n", sizeof(a));		// 400
	printf("sizeof(a[100]) : %d\n", sizeof(a[100]));	// 4
	printf("sizeof(&a) : %d\n", sizeof(&a));	// 4
	printf("sizeof(&a[0]) : %d\n", sizeof(&a[0]));	// 4
	printf("sizeof(xiaozhi) : %d\n", sizeof("xiaozhi"));	// 8
	printf("sizeof(s) : %d\n", sizeof(s));	// 4
	printf("sizeof(*s) : %d\n", sizeof(*s));	// 1
}

int b[100];

void fun(int b[100])
{
	printf("b is globe, sizeof(b) : %d\n",sizeof(b));	// 4
}

int array_cal(void)
{
	int a[5]={1,2,3,4,9};
	int *ptr1 = (int*)(&a + 1);	//  &a+1 = &a + 5 * sizeof(int),也就是下一个数组的首地址.
	int *ptr2 = (int*)((int)a + 1);	// a+1 为a[1].然后把这个地址强制转换成int*类型的值赋给ptr2,
									// 也就是说*ptr2的值应该为元素a[0]第二个字节的连续4个byte内容.
									// 因为是小端模式,所以值为0x2000000   a[1]000000
	int temp = (int)(&a + 1 );	// &a+1 = &a + 5 * sizeof(int),也就是下一个数组的首地址.

	printf("temp - : %d, 0x%x, 0x%x, 0x%x\n", temp, *ptr1, ptr1[-1], *ptr2);

	return 0;
}

enum color
{
	GREEN = 1,
	RED,
	BLUE,
	GREEN_RED = 10,
	GREEN_BLUE
}color_val;

void enum_color_sizeof(void)
{
	printf("sizeof(color) : %d\n", sizeof(color_val));	// 4
}

typedef int int32;

//unsigned int32 aa;	// error
int32 aa;				// ok

//typedef static int sint32;	// error

char bb[10] = {"asdfasd"};

void a_and_a(void)
{
	char a[5] = {'a', 'b', 'c', 'd'};
	char (*p3)[5] = &a;
	char (*p4)[5] = a;	// warning: initialization from incompatible pointer type [enabled by default]
}

void planar_array(void)
{
	int a[3][2] = {(0,1), (2,3), (4,5)};
	int *p;

	p = a[0];
	printf("%s : %d\n", __FUNCTION__, p[0]);

	printf("(2/(-2) = %d\n",(unsigned int) 2/(-2));	// 0
	printf("(2/(-2) = %d\n",2/(-2));	// -1

	printf("(2%(-2) = %d\n",(unsigned int) 2%(-2));	// 2
	printf("(2%(-2) = %d\n",2%(-2));	// 0
}

int main()
{
	int c[100];

#if 0
	size_len();
	fun(b);	
#endif
	array_cal();
	enum_color_sizeof();


	a_and_a();
	planar_array();


	return 0;
}

